package com.hong.tomcat;

import java.net.URL;
import java.net.URLClassLoader;

/**
 * Created by John on 2019/1/31.
 */
public class UrlClassLoaderTest {

    public static void main(String[] args) throws Exception {
        System.out.println(System.getProperty("java.class.path"));

        // 使用URLClassLoader加载jar包
        URLClassLoader loader0 = new URLClassLoader(new URL[]{
                new URL("file:E:\\IDEAProjects\\tomcat-study\\webapps\\servlet-study-0.0.1.jar")
        },Thread.currentThread().getContextClassLoader());
        Class<?> cls = loader0.loadClass("com.hong.servlet.IndexServlet");
        System.out.println(cls);

        URLClassLoader loader = new URLClassLoader(new URL[]{
                new URL("file:" + "E:\\IDEAProjects\\tomcat-study\\webapps\\servlet-study-0.0.1" + "\\WEB-INF\\classes\\")
        });

        Class<?> clss = loader.loadClass("com.hong.servlet.IndexServlet");
        System.out.println(clss);

    }

}
